(* Copyright 2007 dnAnalytics Project.
 *
 * Contributors to this file:
 * Jurgen Van Gael
 *
 * This file is part of dnAnalytics.  dnAnalytics is licensed under the 
 * Microsoft Public License. See License.txt for a complete copy of the
 * license.
 *)
#light

namespace dnAnalytics.LinearAlgebra

open dnAnalytics.LinearAlgebra

/// A module which implements functional sparse vector operations.
module SparseVector =
    
    /// Create a sparse vector with a given dimension from a list of entry, value pairs.
    let of_list (dim: int) (fl: list<int * float>) =
        let v = SparseVector(dim)
        fl |> List.iter (fun (i, f) -> v.[i] <- f)
        v
    
    /// Create a sparse vector with a given dimension from a sequence of entry, value pairs.
    let of_seq (dim: int) (fs: #seq<int * float>) =
        let v = SparseVector(dim)
        fs |> Seq.iter (fun (i, f) -> v.[i] <- f)
        v